home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / TOOL.C < prev    next >
C/C++ Source or Header  |  1993-09-25  |  13KB  |  449 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*  Tool.c  */
  21.  
  22. #include <externs.h>
  23.  
  24.  
  25. char avl_from_which_file[AVL_MAX_NAME_SIZE + 1];
  26.  
  27. #define AVL_TOOL_MNU_ITEMS  6
  28.  
  29.  
  30. int AVL_MOUNT_TOOL(char *local);
  31.  
  32. void AVL_TOOL_REFER_PCK(AVL_T_TOOL_PTR t)
  33. {
  34.     char this[AVL_MAX_LINEL + 1];
  35.     short i;
  36.     sprintf(this,"WITH %s;", t -> more[avl_cur_tool].with);
  37.     for(i = 0; i < strlen(this); ++i)
  38.         AVL_EDIT_INSERT(this[i]);
  39.     AVL_CURSOR_END();
  40.     AVL_EDIT_ENTER();
  41. }
  42.  
  43. void AVL_TOOL_REFER_PCK_USE(AVL_T_TOOL_PTR t)
  44. {
  45.     char this[AVL_MAX_LINEL + 1];
  46.     short i;
  47.     sprintf(this,"WITH %s; USE %s;"
  48.         , t -> more[avl_cur_tool].with
  49.         , t -> more[avl_cur_tool].with);
  50.     for(i = 0; i < strlen(this); ++i)
  51.         AVL_EDIT_INSERT(this[i]);
  52.     AVL_CURSOR_END();
  53.     AVL_EDIT_ENTER();
  54. }
  55.  
  56. void AVL_TOOL_INSERT_CODE(AVL_T_TOOL_PTR t)
  57. {
  58.     if (AVL_MOUNT_TOOL(t -> menu[avl_cur_tool].source));
  59. }
  60.  
  61. void AVL_TOOL_IDENT(int l)
  62. {
  63.     int i;
  64.     for(i = 0; i < l; ++i)
  65.         AVL_EDIT_INSERT(' ');
  66. }
  67.  
  68. static short avl_tool_in_error = 0;
  69.  
  70. static char avl_tool_new_package[AVL_MAX_LINEL + 1];
  71.  
  72. void AVL_TOOL_INSTANTIATE_PCK(AVL_T_TOOL_PTR t)
  73. {
  74.     char *msg = " Enter the New Package Name ";
  75.     char gen_pars[AVL_MAX_GEN_PARS][AVL_MAX_LINEL + 1];
  76.     char msg2[300];
  77.     AVL_WIN_PTR m = NULL;
  78.     char this[AVL_MAX_LINEL + 1];
  79.     char this2[AVL_MAX_LINEL + 1];
  80.     short i, j;
  81.     int where, where2;
  82.     avl_tool_in_error = 1;    
  83.     where = avl_windows[avl_window].txt_col;
  84.     m = AVL_MAKE_WINDOW(msg,7,4,9,5+62,avl_wnd_bk_color,avl_wnd_color);
  85.     if (AVL_PROMPT(1,1,this2,60)) {
  86.         AVL_DEL_WINDOW(m);
  87.         return;
  88.         }
  89.     AVL_DEL_WINDOW(m);
  90.     sprintf(avl_tool_new_package," USE %s;", this2);
  91.     sprintf(msg2," Parameter Passing for Package %s ", this2);
  92.     msg2[72] = '\0';
  93.     m = AVL_MAKE_WINDOW(msg2,4,3,9+t -> more[avl_cur_tool].n_pars,5+73,avl_wnd_bk_color,avl_wnd_color);
  94.     for(i = 0; i < t -> more[avl_cur_tool].n_pars; ++i)  {
  95. again:
  96.         _settextposition(i+1,1);
  97.         sprintf(msg2," Enter %d parameter (%s)\n",i+1,t -> more[avl_cur_tool].gen_pars[i]);
  98.         msg2[72] = '\0';
  99.         _outtext(msg2);
  100.         gen_pars[i][0] = '\0';
  101.         if (AVL_PROMPT(i+2,3,gen_pars[i],60)) {
  102.             AVL_DEL_WINDOW(m);
  103.             return;
  104.             }
  105.         sprintf(msg2,"Is parameter no. %d ok (Y/N) ?",i+1);
  106.         if (AVL_QUESTION(msg2) == 'N') goto again;
  107.         _settextposition(i+1,1);
  108.         t -> more[avl_cur_tool].gen_pars[i][0] = toupper(t -> more[avl_cur_tool].gen_pars[i][0]);
  109.         sprintf(msg2," %d %s: %-69s"
  110.             , i+1
  111.             , t -> more[avl_cur_tool].gen_pars[i]
  112.             , gen_pars[i]);
  113.         msg2[72] = '\0';
  114.         _outtext(msg2);
  115.         _settextposition(i+2,1);
  116.         sprintf(msg2,"%-72s"," ");
  117.         _outtext(msg2);
  118.         }
  119.     AVL_DEL_WINDOW(m);
  120.     sprintf(this,"WITH %s;", t -> more[avl_cur_tool].with);
  121.     AVL_TOOL_IDENT(where);
  122.     for(i = 0; i < strlen(this); ++i)
  123.         AVL_EDIT_INSERT(this[i]);
  124.     AVL_CURSOR_END();
  125.     AVL_EDIT_ENTER();
  126.     AVL_TOOL_IDENT(where);
  127.     sprintf(this,"PACKAGE %s IS NEW %s(", this2, t -> more[avl_cur_tool].pname);
  128.     for(i = 0; i < strlen(this); ++i)
  129.         AVL_EDIT_INSERT(this[i]);
  130.     where2 = avl_windows[avl_window].txt_col;
  131.     for(i = 0; i < t -> more[avl_cur_tool].n_pars; ++i)  {
  132.         if (i != 0)  {
  133.             avl_windows[avl_window].txt_col = 0;
  134.             avl_windows[avl_window].current_line -> line[0] = '\0';
  135.             AVL_TOOL_IDENT(where2-1);
  136.             AVL_EDIT_INSERT(',');
  137.             }
  138.         for(j = 0; j < strlen(gen_pars[i]); ++j)
  139.             AVL_EDIT_INSERT(gen_pars[i][j]);
  140.         if ((i + 1) == t -> more[avl_cur_tool].n_pars) {
  141.             AVL_EDIT_INSERT(')');
  142.             AVL_EDIT_INSERT(';');
  143.             }
  144.         else {
  145.             AVL_CURSOR_END();
  146.             AVL_EDIT_ENTER();
  147.             }
  148.         }
  149.     avl_tool_in_error = 0;    
  150. }
  151.  
  152.  
  153. void AVL_TOOL_INSTANTIATE_PCK_USE(AVL_T_TOOL_PTR t)
  154. {
  155.     int where, i;
  156.     where = avl_windows[avl_window].txt_col;
  157.     AVL_TOOL_INSTANTIATE_PCK(t);
  158.     if (avl_tool_in_error) 
  159.         return;
  160.     AVL_TOOL_IDENT(where);
  161.     for(i = 0; i < strlen(avl_tool_new_package); ++i)
  162.         AVL_EDIT_INSERT(avl_tool_new_package[i]);
  163.     AVL_CURSOR_END();
  164.     AVL_EDIT_ENTER();
  165. }
  166.  
  167. void AVL_TOOL_HELP(AVL_T_TOOL_PTR t)
  168. {
  169.     AVL_HELP(t -> more[avl_cur_tool].help);
  170. }
  171.  
  172.  
  173.  
  174. TOOL_SIZE avl_tool_mnu[AVL_TOOL_MNU_ITEMS] = 
  175.     {{"A Refer Package            ",AVL_TOOL_REFER_PCK}
  176.     ,{"B Refer Package & USE      ",AVL_TOOL_REFER_PCK_USE}
  177.     ,{"C Insert Source Code       ",AVL_TOOL_INSERT_CODE}
  178.     ,{"D Instantiate Package      ",AVL_TOOL_INSTANTIATE_PCK}
  179.     ,{"E Instantiate Package & USE",AVL_TOOL_INSTANTIATE_PCK_USE}
  180.     ,{"F Help                   "  , AVL_TOOL_HELP}
  181.     };
  182.     
  183.  
  184.  
  185. void AVL_GET_TOOLS(AVL_T_TOOL_PTR tool)
  186. {
  187.     FILE *fp, *fopen();
  188.     char s[200], s2[200];
  189.     char *pl;
  190.     int i, j, k, l;
  191.     tool -> no_menu = 0;
  192.     pl = getenv("ADAED");
  193.     if (pl == NULL)
  194.         pl=getenv("adaed");
  195.     if (pl != NULL)  
  196.         sprintf(s,"%s%c%s",pl,'\\',AVL_TOOL_FNAME);
  197.     else  {
  198.         AVL_ERROR("Set the ADAED environment variable first (see readme.gw).");
  199.         return;
  200.         }        
  201.     fp = fopen(s,"r");
  202.     if (fp == NULL)  {
  203.         sprintf(s2,"Can't access file \'%s\'", s);
  204.         AVL_ERROR(s2);
  205.         return;
  206.         }
  207.     while ( fgets(s2,200,fp) != NULL)  {
  208.         if (tool -> no_menu >= AVL_TOOL_MAX)  {
  209.             sprintf(s2,"Can't process more than %d tools. Rest ignored!", AVL_TOOL_MAX);
  210.             AVL_ERROR(s2);
  211.             break;
  212.             }
  213.         for(i = 0; s2[i] != '@' && s2[i] != '$' && i < AVL_TOOL_MAX_MENU; ++i)
  214.             tool -> menu[tool -> no_menu].menu_item[i] = s2[i];
  215.         tool -> menu[tool -> no_menu].menu_item[i] = '\0';
  216.         while (s2[i] != '$') ++i;
  217.         ++i;
  218.         for(j = 0; !((s2[i] == '\0') || (s2[i] == ' ') || (s2[i] == '\n')) && j < AVL_MAX_FILE_NAME; ++j, ++i)
  219.             tool -> menu[tool -> no_menu].source[j] = s2[i];
  220.         tool -> menu[tool -> no_menu].source[j] = '\0';
  221.         while (s2[i] != '$') ++i;
  222.         ++i;
  223.         for(j = 0; !((s2[i] == '\0') || (s2[i] == ' ') || (s2[i] == '\n')) && j < AVL_MAX_LINEL; ++j, ++i)
  224.             tool -> more[tool -> no_menu].help[j] = s2[i];
  225.         tool -> more[tool -> no_menu].help[j] = '\0';
  226.         while (s2[i] != '$') ++i;
  227.         ++i;
  228.         tool -> more[tool -> no_menu].type = s2[i];
  229.         /* Get the package name */
  230.         while (s2[i] != '$') ++i;
  231.         ++i;
  232.         for(j = 0; !((s2[i] == ' ') || (s2[i] == '\0') || (s2[i] == '\n')) && j < AVL_MAX_LINEL; ++j, ++i)
  233.             tool -> more[tool -> no_menu].with[j] = s2[i];
  234.         tool -> more[tool -> no_menu].with[j] = '\0';
  235.         if (tool -> more[tool -> no_menu].type == 'I')  {
  236.             /* Get the full package name  */
  237.             while (s2[i] != '$') ++i;
  238.             ++i;
  239.             for(j = 0; !((s2[i] == ' ') || (s2[i] == '\0') || (s2[i] == '\n')) && j < AVL_MAX_LINEL; ++j, ++i)
  240.                 tool -> more[tool -> no_menu].pname[j] = s2[i];
  241.             tool -> more[tool -> no_menu].pname[j] = '\0';
  242.             while (s2[i] != '$') ++i;
  243.             ++i;
  244.             /* Now get the number of parameters */
  245.             tool -> more[tool -> no_menu].n_pars = 0;
  246.             while(isdigit(s2[i])) 
  247.                 tool -> more[tool -> no_menu].n_pars = 
  248.                     tool -> more[tool -> no_menu].n_pars * 10 
  249.                                                          + (s2[i++] - '0');
  250.             /* Get an user message to prompt for each parameter */
  251.             for(k = 0; k < tool -> more[tool -> no_menu].n_pars && 
  252.                fgets(tool -> more[tool -> no_menu].gen_pars[k],200,fp) != NULL; 
  253.                ++k)  {
  254.                 l = strlen(tool -> more[tool -> no_menu].gen_pars[k]); 
  255.                 if (tool -> more[tool -> no_menu].gen_pars[k][l - 1] == '\n')
  256.                     tool -> more[tool -> no_menu].gen_pars[k][l - 1] = '\0'; 
  257.                 }
  258.             if (k != tool -> more[tool -> no_menu].n_pars)  {
  259.                 sprintf(s,"Invalid package parameter descriptor : %s", 
  260.                     tool -> menu[tool -> no_menu].menu_item);
  261.                 AVL_ERROR(s);
  262.